package be.jabapage.gui;

import java.awt.Dimension;
import java.awt.HeadlessException;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

import org.apache.log4j.Logger;

import be.jabapage.util.HibernateUtil;
import be.jabapage.util.PropertiesSingleton;

public class SnookerApp extends JFrame {

	private Logger logger = Logger.getRootLogger();
	private JDesktopPane desk;

	/**
	 * @throws HeadlessException
	 */
	public SnookerApp(String title) throws HeadlessException {
		super(title);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		desk = new JDesktopPane();
		setContentPane(desk);
		SnookerMenuBar menuBar = new SnookerMenuBar(this);
		this.setJMenuBar(menuBar);
		this.reSize();

	}

	public void reSize() {
		PropertiesSingleton props = PropertiesSingleton.getInstance();
		int width = Integer.parseInt(props.getGUIProperty("application.width"));
		int height = Integer.parseInt(props
				.getGUIProperty("application.height"));
		logger.debug("width = " + width + " height = " + height);
		this.setSize(new Dimension(width, height));
		reSizeAll();
		this.setVisible(true);
	}

	public void reSizeAll() {
		JInternalFrame [] frames = desk.getAllFrames();
		for (int i = 0; i < frames.length; i++) {
			SnookerAppInternalFrame frame = (SnookerAppInternalFrame) frames[i];
			frame.reSize();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HibernateUtil.getSessionFactory();
		PropertiesSingleton singleton = PropertiesSingleton.getInstance();
		SnookerApp app = new SnookerApp(singleton.getString("app.title"));

	}

}
